package com.team2.s3hrjyxm.qxglcontroller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team2.s3hrjyxm.QxglService.UserService;
import com.team2.s3hrjyxm.pojo.Role;
import com.team2.s3hrjyxm.pojo.Users;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
public class UserController {
     @Autowired
    UserService service;

       @RequestMapping("userquery")
       public String UserQuery(Map map,
               @RequestParam(defaultValue = "1",required = false) Integer startPage,
              @RequestParam(defaultValue = "5",required = false) Integer PageSize){

           PageHelper.startPage(startPage, PageSize );//使用分页插件
           List<Map> list= service.userquery();
           PageInfo pageInfo=new PageInfo(list, 5); //保存分页信息
           map.put("items", list);
           map.put("pageInfo", pageInfo); //绑定分页信息
           return "page/power/user_list.html";
       }


      @RequestMapping("user_add")
        public String user_add(Map map){
          List<Role>  list2=service.yhsfquery();
           map.put("itemss", list2);
          return "page/power/user_add.html";
    }
    @RequestMapping("user_adds")
      public String user_adds(Users r){
             service.useradd(r);

        return "page/power/success.html";
    }

       @RequestMapping("user_update1")
       public String user_update1(int u_id,Map map,Map map2){
           Map map1=service.userquerybyid(u_id);
               map.put("map", map1);
           List<Role>  list2=service.yhsfquery();
            map2.put("itemss", list2);
           return "page/power/user_edit.html";
    }
      @RequestMapping("user_delete")
        public String  userdelete(int u_id){
               service.userdelete(u_id);
            return "page/power/success.html";
    }
        @RequestMapping("user_update2")
       public String user_update2(Users u){
             service.userupdate(u);
        return "page/power/success.html";
    }

}
